package network;

import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.ServerSocket;
import java.net.Socket;

public class Server {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		ServerSocket ss = new ServerSocket(8080);
		Socket s;
		while(true){
			try{
				s = ss.accept(); 
				BufferedReader br = new BufferedReader(new InputStreamReader(s.getInputStream()));
				String total = "";
				String in = br.readLine();
				while(in != null && !in.equals("END")){
					total += in + "\n";
					in = br.readLine();
				}
				System.out.println(total);
				BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(s.getOutputStream()));
				bw.write(total);
				bw.newLine();
				bw.write("END");
				bw.newLine();
				bw.flush();
				s.close();
			} catch(Exception e){e.printStackTrace();}
		}

	}

}
